--
-- Author: mm
-- Date: 2018-04-09 19:02:27
-- NewguildTips
-- 公会tips

local string_gsub = string.gsub

local panel_2_originWidth = 0 -- panel2原始宽
local panel_2_originHeight = 0 -- panel2原始高
local panel_originWidth = 0 -- panel原始宽
local panel_originHeight = 0 -- panel原始高

local offsetHeight = 20 -- 距离上边距高
local originHeight = 0 -- 文本原始高

local ClassRef = app.mvc.createPanelClass(...)

function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewGuildMemberInfoNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._ui.icon:setVisible( false )
	self._ui.num:setVisible( false )

	originHeight = self._ui.userContent_1:getContentSize().height

	panel_2_originWidth, panel_2_originHeight = self._ui.Panel_2:getContentSize2()
	local diffHeight = panel_2_originHeight/2
	self._ui.Panel_2:setContentSize( cc.size( panel_2_originWidth, panel_2_originHeight - diffHeight + offsetHeight ) )

	panel_originWidth, panel_originHeight = self._ui.Panel:getContentSize2()
	self._ui.Panel:setContentSize( cc.size( panel_originWidth, panel_originHeight - diffHeight + offsetHeight ) )
	self:setContentSize( self._ui.Panel:getContentSize() )

	ccui.Helper:doLayout( self )
end

function ClassRef:setNameStr( str )
	if str and "" ~= str then
		self._ui.name:setString( str )
	end
end

function ClassRef:setContent2Str(strContent, num)
	self._ui.userContent_1:setVisible(true)
	self._ui.userContent_2:setVisible(true)	
	if strContent then
		self._ui.userContent_2:setString(strContent)
	end
	if num then
		self._ui.userContent_1:setString(num)
		self._ui.userContent_1:setColor(cc.c3b(255, 225, 132))
	end
	-- 以下：自动调整panel高
	local textHeight = 0
	local _, count = string_gsub( strContent, "\n", "\n" )
	if 0 < count then -- 多行？
		textHeight = originHeight * count		
	end	
	-- self._ui.bg:setContentSize( cc.size( panel_originWidth, panel_originHeight + textHeight))
	self._ui.Panel:setContentSize( cc.size( panel_originWidth, panel_originHeight + textHeight + offsetHeight ))
	self:setContentSize( cc.size( panel_originWidth, panel_originHeight + textHeight + offsetHeight ))

	
	ccui.Helper:doLayout( self )
end
function ClassRef:setContentStr( str )
	if str and "" ~= str then
		self._ui.userContent_1:setString( str )
		self._ui.userContent_1:getVirtualRenderer():setDimensions( 290, 0 )
		local size = self._ui.userContent_1:getVirtualRendererSize()
		self._ui.userContent_1:setContentSize(290,size.height)

		self._ui.Panel_2:setContentSize( cc.size( panel_2_originWidth, size.height +  offsetHeight) )
		self._ui.Panel:setContentSize( cc.size( panel_originWidth, panel_originHeight - panel_2_originHeight + size.height +  offsetHeight  ) )
		self:setContentSize( self._ui.Panel:getContentSize() )
		ccui.Helper:doLayout( self )
	end
end


return ClassRef
